<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@include file="/WEB-INF/mytag.jspf"%>
<!DOCTYPE html>
<html>
<head>
<base href="<%=basePath%>">
<title>美发开单</title>
<script type="text/javascript">
    $("#search-btn").on("click",function(){
    	searchVip();
	});
    
    function billingFlow(flag){
    	var vipId = $("#vipId").val();
    	if(flag==1&&!vipId){
    		Comm.msg("请先搜索会员");
    		return;
    	}
    	var url = "${ctx}/weixin/employee/billingFlow";
    	if (flag==1&&vipId) {
    		url = url +"?vipId="+vipId;
    	}
        window.location.href=url;
    }
    
    function detail(){
    	var vipId = $("#vipId").val();
        if (!vipId) {
        	Comm.msg("请先搜索会员");
            return;
        }
        window.location.href="${ctx}/weixin/employee/vipDetail/"+vipId;
    }
    
    function searchVip(){
    	var phone = $("#phone").val();
        if (!phone) {
        	Comm.msg("请输入会员手机号");
            return;
        }
		var $btn = $(this);
		$btn.attr("disabled","disabled");
		//$("form").submit();
		
		$.ajax({
			type : 'POST',
            url: "${ctx}/weixin/employee/searchVip",
            dataType: "json",
            data:"phone="+phone,
            success: function (data) {
            	$btn.prop("disabled",false);
                if (data.success) {
                	$("#vipId").val(data.params.vip.vipId);
                	$("#sp-phone").text(data.params.vip.vipNo);
                	$("#name").text(data.params.vip.name);
                	$("#sex").text(data.params.vip.sex=='F'?'女':'男');
                	
                	if(data.params.order){
                		$("#service_item").text(data.params.order.serviceNames);
                		var date = new Date(data.params.order.creTime.replace(/-/g, "/"));
        				var lastTime = date.format("yyyy/M/d");
                    	$("#last_time").text(lastTime+"-"+data.params.order.shopName);
                	}
					if(data.params.appoint){
						$("#order_service_item").text(data.params.appoint.serviceItemNames);
						var date = new Date(data.params.appoint.appointmentTime.replace(/-/g, "/"));
	                	$("#order_time").text(date.format("yyyy/M/d-H:mm"));
	                	$("#order_employee").text(data.params.appoint.employeeName);
                	}
                }else{
                	Comm.msg(data.msg);
                	$(".vip-info").text("");
                	$("#vipId").val("");
                }
            },
            error: function () {
            	Comm.msg("搜索失败，请重试");
            	$btn.prop("disabled",false);
            }
        });
    }
    
    if($("#phone").val()){
    	searchVip();
    }
    
</script>
</head>
<body>
	<div style="padding-bottom:40px;">
		<div class="am-g app-search-g">
			<div class="am-u-sm-12 am-padding-sm">
				<div class="am-input-group">
					<input id="phone" type="number" class="am-form-field am-radius" placeholder="请输入会员手机号码以搜索">
					<span class="am-input-group-btn"><button id="search-btn" class="am-btn am-btn-white am-text-blue am-radius" type="button"><span class="am-icon-search"></span></button></span>
				</div>
			</div>
		</div>
		<input id="vipId" type="hidden"></input>
		<h4 class="app-title-secondary">顾客信息</h4>
		<ul class="am-list am-list-static am-padding-left-sm am-margin-0">
			<li>手机号码：<span id="sp-phone" class="vip-info"></span></li>
			<li><ul class="am-avg-sm-2"><li>姓名：<span id="name" class="vip-info"></span></li><li>性别：<span id="sex" class="vip-info"></span></li></ul></li>
			<li>上次美发时间：<span id="last_time" class="vip-info"></span></li>
			<li>上次美发项目：<span id="service_item" class="vip-info"></span></li>
		</ul>
		<h4 class="app-title-secondary">预约信息</h4>
		<ul class="am-list am-list-static am-padding-left-sm am-margin-0">
			<li>预约项目：<span id="order_service_item" class="vip-info"></span></li>
			<li>预约时间：<span id="order_time" class="vip-info"></span></li>
			<li>预约美发师：<span id="order_employee" class="vip-info"></span></li>
		</ul>
		<a href="javascript:void(0)" class="am-text-white" onclick="detail();"><h4 class="app-title">会员详情<span class="am-fr am-icon-angle-right"></span></h4></a>
		<ul class="am-avg-sm-2 app-fix-bottom">
			<li><button class="am-btn am-btn-lg am-btn-landiao am-btn-block" onclick="billingFlow(1);">会员</button></li>
			<li><button class="am-btn am-btn-lg am-btn-white am-btn-block" onclick="billingFlow(0);">非会员</button></li>
		</ul>
	</div>
</body>
</html>
